Add MA0186: Report missing nullable attributes on Equals and TryGetValue parameters#998
Conversation
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
|
@copilot Can you regenerate the documentation? |
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
|
@copilot the original issue also ask for something about idictionary #975 (comment) |
I've implemented support for:
I'm having difficulty with explicit interface implementations ( Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
- Skip reporting diagnostic for IEquatable<T>.Equals when T is a value type - Simplify IEquatable detection logic to work for both public and explicit implementations - Add test for value type scenario Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
- Use IsInterfaceImplementation() and GetImplementingInterfaceSymbol() helpers - Check OverriddenMethod chain to verify object.Equals override - Add tests for #nullable enable/disable scenarios - NullableAnnotation check already ensures nullable is enabled Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot The original issues mentioned another method to handle Another - much less common - example would be missing [MaybeNullWhen(false)] on value argument of an implementation of IDictionary<TKey,TValue>.TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value). |
- Detect missing [MaybeNullWhen(false)] on value parameter of IDictionary<TKey, TValue>.TryGetValue implementations - Add tests for TryGetValue scenarios - Update documentation to cover both Equals and TryGetValue patterns Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Done in commit 9ee4a9f. Now detecting missing Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Implementation
This rule detects two patterns of missing nullable attributes:
[NotNullWhen(true)]on parameters ofEquals(object?)overrides andIEquatable<T>.Equals(T?)implementations[MaybeNullWhen(false)]on thevalueparameter ofIDictionary<TKey, TValue>.TryGetValueimplementationsBoth patterns improve nullable reference type analysis by helping the compiler understand nullability flow based on method return values.
Configuration
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.